var path = require( "path" );
var HtmlwebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var CleanWebpackPlugin = require('clean-webpack-plugin');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var packageInfo = require('./package.json');
var webpack = require('webpack');
var srcPath = path.join(__dirname, 'src');

module.exports = {
  entry: {
    bundle:path.resolve( './src/index.js' )
  },
  output: {
  	path: path.resolve("./dist"),
    filename: '[hash:6]_[name].js'
  },
  devServer:{
      contentBase: './dist',
      compress: true,
      port:3085
  },
  plugins: [
    //copy文件到输出目录
    new CopyWebpackPlugin([
        {context: 'src/js/components/', from: '**/*.html' , to: packageInfo.version + '_components/'},
        {context: path.join(srcPath,'images'),from: '**/*.*' ,to:'images'}
    ]),
    //压缩打包的文件
     // new webpack.optimize.UglifyJsPlugin({
     //     compress: {
     //         //supresses warnings, usually from module minification
     //         warnings: false
     //     }
     // }),
    new ExtractTextPlugin("[name].css"),
  	new HtmlwebpackPlugin({
      title: 'tscl-cloud',
      filename: 'login.html',
      template: './src/login.html',
      chunks: ['bundle']
    }),
    new CleanWebpackPlugin(['dist'],{
      verbose: true
    })
  ],
  module: {
  	rules: [
  		{
        test: /\.html$/,
        use:[
            {  loader: 'raw-loader',options:{exclude:/node_modules/} }
        ]
      },
      { //引入css
          test: /\.css$/,
          use:[
              { loader: "css-loader" ,options: {modules: true} },
              { loader: "style-loader"}
          ]
      },
      {//引入less
          test: /\.less$/,
          use:ExtractTextPlugin.extract({
            fallback: "style-loader",
            use: [{
                      loader: 'css-loader',
                      options:{
                          minimize: true //css压缩
                      }
                  },"less-loader"]
          })
      }
  	]
  },
  externals:{
  	"angular":"angular"
  },
  resolve: {
      alias: {
          "versionNum": path.resolve(__dirname,"package.json"),
          "mainModule": path.join(__dirname,"src/main.js")
      }
  }
};